﻿using System;
using System.Collections.Generic;
using System.Xml.Serialization;

namespace QuickAppLibrary
{
    ///<summary> 
    /// Provides Enumeration services for the PriorEmployerCollection Class; 
    /// Implements IEnumerator
    ///</summary>

    [Serializable, XmlInclude(typeof(PriorEmployer))]
    class PriorEmployerEnumerator : IEnumerator<PriorEmployer>
    {
        private PriorEmployerCollection _priorCollection;
        private int curIndex;
        private PriorEmployer curEmp;

        /// <summary>
        /// Construct a PriorEmployerEnumerator Object
        /// </summary>
        /// <param name="employerCollection"></param>
        public PriorEmployerEnumerator(PriorEmployerCollection employerCollection)
        {
            _priorCollection = employerCollection;
            curIndex = -1;
            curEmp = default(PriorEmployer);
        }

        /// <summary>
        /// Moves to next iteration of a PriorEmployerCollection
        /// </summary>
        /// <returns>Boolean Value</returns>
        public bool MoveNext()
        {
            //Avoid going beyond the end of collection
            if (++curIndex >= _priorCollection.Count)
            {
                return false;
            }
            else
            {
                //Set current box to next item in collection
                curEmp = _priorCollection[curIndex];
            }
            return true;
        }

        /// <summary>
        /// Resets the index of the Enumerator
        /// </summary>
        public void Reset() { curIndex = -1; }

        //Dispose Object Implementation; intentionally blank
        void IDisposable.Dispose() { }

        /// <summary>
        /// Read-only Property for the current PriorEmployer Object
        /// </summary>
        public PriorEmployer Current
        {
            get { return curEmp; }
        }

        object System.Collections.IEnumerator.Current
        {
            get { return Current; }
        }
    }
}
